//
//  BTRootImageTItleVIew.m
//  BTShike2
//
//  Created by 刘军林 on 2019/11/25.
//  Copyright © 2019 刘军林. All rights reserved.
//

#import "BTRootImageTItleVIew.h"

@implementation BTRootImageTItleVIew

-(instancetype) initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self addSubview:self.imageView];
        [self addSubview:self.title];
        
        [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.offset(0.f);
            make.top.equalTo(self).offset(16.0f);
            make.height.mas_equalTo(55.f);
            make.width.mas_equalTo(55.f);
        }];
        self.imageView.layer.cornerRadius = 27.5f;
        self.imageView.layer.masksToBounds = YES;
        
        [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.offset(0.f);
            make.top.equalTo(self.imageView.mas_bottom).offset(1);
            make.left.right.offset(0.0f);
        }];
        
        self.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        tap.numberOfTouchesRequired = 1;
        tap.numberOfTapsRequired = 1;
        [self addGestureRecognizer:tap];
    }
    return self;
}

#pragma mark - event response
-(void) tapAction:(UITapGestureRecognizer *) gesture
{
    if ([self.delegate respondsToSelector:@selector(rootImageViewDidTap:)]) {
        [self.delegate rootImageViewDidTap:self];
    }
}

#pragma mark - getters
- (UIImageView *)imageView {
    if (!_imageView) {
        _imageView = [[UIImageView alloc] init];
    }
    return _imageView;
}

- (UILabel *)title {
    if (!_title) {
        _title = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Regular", 15.0) titleColor:HEX_RGB(kTitleDrakBlackColor) textAlignment:ZZTextAlignmentCenter];
    }
    return _title;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
